@extends('admin_system.layout.layout')
@section('content')
    <br>
    <div class="container-fluid">
        <div class="panel panel-info">
            <div class="panel-heading">
                <h3 class="panel-title text-center">学习官</h3>
            </div>
            <div class="panel-body">
                <table class="table table-condensed table-hover">
                    <thead>
                    <tr>
                        <th>CLO</th>
                        <th>CLO图片</th>
                        <th>CLO标题</th>
                        <th>个人简历</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data as $k=>$v)
                        <form action="{{route('lessons_clo_update')}}" method="post" enctype="multipart/form-data">
                            {{csrf_field()}}
                            <tr id="clo_del_{{$v->clo_id}}">
                                <td>
                                    <select name="user_id" id="" class="form-control">
                                        @foreach($clos as $kk=>$vv)
                                            <option value="{{$vv->user_id}}"
                                                    @if($vv->user_id==$v->user_id) selected
                                                    @endif>{{$vv->YourName}}</option>
                                        @endforeach
                                    </select>
                                    <input type="hidden" value="{{$v->clo_id}}" name="clo_id">
                                </td>
                                <td>
                                    <input type="url" readonly="readonly" name="user_img" class="form-control"
                                           value="{{$v->user_img}}">
                                </td>
                                <td>
                                    <input type="text" readonly="readonly" name="title" class="form-control"
                                           value="{{$v->title}}">
                                </td>
                                <td>
                                    <div>{!! str_limit(trim($v->introduce),10) !!}</div>
                                </td>
                                <td>
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-info">
                                            <a href="{{route('lessons_clo_show',['id'=>$v->clo_id])}}">编辑</a>
                                        </button>
                                        <button type="button" class="btn btn-danger" id="del"
                                                onclick="clo_del('{{$v->clo_id}}')">删除
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        </form>
                    @endforeach
                    </tbody>
                </table>
                {{$data->links()}}
                <hr>
                <div class="btn-group">
                    <button type="button" class="btn btn-danger" id="add_clo" onclick="add_clo()">添加</button>
                    @include('admin_system.studyCenter.cloAdd',['clos'=>$clos])
                </div>
            </div>
        </div>
    </div>
    <script>
        @if(session('success'))
        $.notify({
            message: '{{session('success')}}'
        }, {
            type: 'danger'
        })
        @endif

        @if(session('errors'))
        $.notify({
            message: "{{session('errors')}}"
        }, {
            type: 'danger'
        })

        @endif

            clo_del = function (id) {
            $.ajax({
                url: '{{route('lessons_clo_del')}}',
                type: 'get',
                data: {'id': id},
                dataType: 'json',
                beforeSend: function () {
                    $('#del').text('正在删除中。。。').attr('disabled', 'disabled')
                },
                success: function (data) {
                    if (data.code == 200) {
                        $('#del').text('删除').removeAttr('disabled')
                        $(eval('"#clo_del_' + id + '"')).remove();
                        $.notify(data.msg);
                    } else if (data.code == 400) {
                        $('#del').text('删除').removeAttr('disabled')
                        $.notify(data.msg);
                    }
                }
            })
        }

        function add_clo() {
            $('#modal-clo').modal('show');
        }
    </script>
@stop()
